﻿using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SerializeNode))]
public class SerializeNodeEditor : Editor
{
    private SerializeNode gizmos;

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        gizmos = target as SerializeNode;
        gizmos.FlushData();

        EditorGUI.BeginChangeCheck();
        gizmos.maskIdx = EditorGUILayout.MaskField("选择组件", gizmos.maskIdx, gizmos.names);
        DrawProperties();

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }

    void DrawProperties()
    {
        foreach (var serialize in gizmos.keyObjDatas)
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("name:", GUILayout.Width(40));
                EditorGUILayout.SelectableLabel(serialize.name, GUILayout.Height(20));
                EditorGUILayout.LabelField("com:", GUILayout.Width(40));
                EditorGUILayout.ObjectField(serialize.com, typeof(Component), false);
            }
        }
    }
}